<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------

namespace app\api\service\card;



use app\admin\model\wms\Rating;
use app\api\model\card\Category;
use app\core\base\BaseApiService;
use app\service\core\card\CoreCardCategoryService;


/**
 *  卡牌分类服务层
 */
class CardCategoryService extends BaseApiService
{
     public function __construct()
     {
          parent::__construct();
          $this->model = new Category();
     }

     /**
      * 查询商品分类树结构
      * @param string $field
      * @param string $order
      * @return array
      */
     public function getTree()
     {
          return ( new CoreCardCategoryService() )->getTree([ [ 'status', '=', 1 ] ]);
     }



     /**
      * 获取商品分类列表
      * @param array $where
      * @param string $field
      * @return array
      */
     public function getList(array $where = [],$field = 'id,name,pid,weigh')
     {
          $order = 'weigh desc,create_time desc';
          return $this->model->where([ [ 'status', '=', 1 ] ])->withSearch([ "category_name", 'category_id', 'pid' ], $where)->field($field)->order($order)->select()->toArray();
     }

     //获取稀有度分类
     public function getRating()
     {
          return Rating::select()->toArray();
     }
     //获取稀有度一级分类下的所有分类
     public function getRatingByPid($data)
     {
          return Rating::where(['category_id'=>$data['pid']])->select()->toArray();
     }

}
